package com.lmx.persistence.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lmx.common.constants.CommonConstants;
import com.lmx.persistence.service.common.BaseCrudServiceImpl;
import com.lmx.repoDomain.tmodel.CustomerDynamic;
import com.lmx.repoDomain.tmodel.VideoInfo;

/**
 * 老人动态Service实现
 *
 * @author ytche
 * @date 2017年8月21日
 *
 */
@Service
public class CustomerDynamicServiceImpl extends
		BaseCrudServiceImpl<CustomerDynamic> implements CustomerDynamicService {
	@Autowired
	private VideoInfoService videoService;

	@Override
	public CustomerDynamic create(CustomerDynamic entity) {
		if (CommonConstants.DYNAMIC.VIDEO.lable().equals(
				entity.getDynamicType().getId())
				&& entity.getVideoInfo() != null) {
			entity.setVideoInfo(this.videoService.save(entity.getVideoInfo()));
		}
		if (entity.getReadStatus() == null) {
			entity.setReadStatus(CommonConstants.DEFAULT_STATUS_NO_0);
		}
		return super.create(entity);
	}

	@Override
	public CustomerDynamic update(CustomerDynamic entity) {
		if (entity.getDelStatus().equals(CommonConstants.DEL_STATUS_YES_1)
				&& CommonConstants.DYNAMIC.VIDEO.lable().equals(
						entity.getDynamicType().getId())
				&& entity.getVideoInfo() != null) {
			VideoInfo videoInfo = entity.getVideoInfo();
			videoInfo.setDelStatus(CommonConstants.DEL_STATUS_YES_1);
			entity.setVideoInfo(this.videoService.update(videoInfo));
			;
		}
		return super.update(entity);
	}
}
